package com.it.goods.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.it.goods.pojo.Brand;
import com.it.goods.pojo.Category;
import com.it.goods.pojo.Goods;
import com.it.goods.pojo.Image;
import com.it.goods.service.BrandService;
import com.it.goods.service.CategoryService;
import com.it.goods.service.GoodsService;
import com.it.goods.service.ImageService;
@Controller
public class indexController {

	
    @Autowired
    private ImageService imageService;
	
    @Autowired
    private BrandService brandService;
    @Autowired
    private CategoryService categoryService;
	
    @Autowired
    private GoodsService goodsService;
    
    @RequestMapping("/index")
    public String findAllbrand(Model model, @RequestParam(value = "pageNum", defaultValue = "0") int pageNum, @RequestParam(value = "pageSize", defaultValue = "8") int pageSize){

        
        //调用Service实现查询
        List<Category> list = categoryService.findByParentId(0); 
        HashMap<Integer, List<Category>> hashMap1 = new HashMap<Integer, List<Category>>();
        HashMap<Integer, List<Category>> hashMap2 = new HashMap<Integer, List<Category>>();
        for (Category category : list) {
        	List<Category> findByParentId = categoryService.findByParentId(category.getId());
			hashMap1.put(category.getId(), findByParentId);
        	 for (Category category2 : findByParentId) {
        		 List<Category> findByParentId2 = categoryService.findByParentId(category2.getId());
        		 hashMap2.put(category2.getId(), findByParentId2);
        	 }
		}
 

        model.addAttribute("hashMap1",hashMap1);
        model.addAttribute("hashMap2",hashMap2);
        model.addAttribute("brandList",list);
        
        
       PageInfo<Goods> findAlls = goodsService.findPage(pageNum, pageSize);
       model.addAttribute("findAlls", findAlls.getList());
       model.addAttribute("findpage", findAlls);
       
        
        List<Goods> findAll = goodsService.findAll();
        model.addAttribute("findAll", findAll);
    
        
        List<Image> findAllimage = imageService.findAll();
        
        model.addAttribute("findAllimage", findAllimage);
        
      
        
        
        
        return "index";
    }
}
